package fr.emse.tatiana.scoresheetvisualisation;


import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;

import fr.emse.tatiana.graphical.DisplayRule;
import fr.emse.tatiana.replayable.IReplayableModel;
import fr.emse.tatiana.replayable.analysis.Link;
import fr.emse.tatiana.replayable.analysis.graph.ConnectionEditPart;

public class DisplayPartFactory implements EditPartFactory {
	
	private Map<Object,EditPart> objectmap;
	private List<DisplayRule> rules;
	
	public DisplayPartFactory(List<DisplayRule> rules) {
		super();
		objectmap = new Hashtable<Object, EditPart>();
		this.rules = rules;
	}

	public EditPart createEditPart(EditPart context, Object model) {
		AbstractGraphicalEditPart part = null; 
        
        if (model instanceof IReplayableModel) {
        	part = new ReplayableModelPart((IReplayableModel) model);
        } else if (model instanceof Link) {
        	part = new ConnectionEditPart() {

				@Override
				protected void createEditPolicies() {
					// don't install any edit policies
				}
        		
        	};
        	part.setModel(model);
        } else {
        	part = new EventPart(model, rules);
        } 
     
        part.setParent(context);
        objectmap.put(model,part);
        
        return part;
	}
	
	public EditPart getEditPart(Object model) {
		return objectmap.get(model);
	}

}
